{% load static %}

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>心灵树洞 - 匿名倾诉你的心事</title>
    <style>
        /* 保持原有CSS样式不变 */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Microsoft YaHei', sans-serif;
        }

        body {
            background-color: #fff5f7;
            color: #555;
            line-height: 1.6;
        }

        .container {
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
        }

        header {
            text-align: center;
            margin-bottom: 30px;
            padding: 20px 0;
            background-color: #ffb6c1;
            color: white;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        }

        h1 {
            font-size: 2.2em;
            margin-bottom: 10px;
        }

        .description {
            font-size: 1.1em;
            opacity: 0.9;
        }

        .post-form {
            background-color: white;
            padding: 25px;
            border-radius: 8px;
            margin-bottom: 30px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        }

        textarea {
            width: 100%;
            min-height: 150px;
            padding: 15px;
            border: 1px solid #ffd1dc;
            border-radius: 5px;
            font-size: 1em;
            margin-bottom: 15px;
            resize: vertical;
            transition: border 0.3s;
        }

        textarea:focus {
            outline: none;
            border-color: #ffb6c1;
            box-shadow: 0 0 0 2px rgba(255, 182, 193, 0.2);
        }

        .btn {
            background-color: #ffb6c1;
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 5px;
            cursor: pointer;
            font-size: 1em;
            transition: all 0.3s;
        }

        .btn:hover {
            background-color: #ff8fab;
            transform: translateY(-1px);
        }

        .posts-container {
            margin-top: 30px;
        }

        .post {
            background-color: white;
            padding: 20px;
            border-radius: 8px;
            margin-bottom: 20px;
            box-shadow: 0 2px 5px rgba(255, 182, 193, 0.2);
            position: relative;
            transition: transform 0.3s;
        }

        .post:hover {
            transform: translateY(-3px);
            box-shadow: 0 4px 8px rgba(255, 182, 193, 0.3);
        }

        .post-content {
            margin-bottom: 15px;
            white-space: pre-wrap;
        }

        .post-meta {
            font-size: 0.9em;
            color: #888;
            text-align: right;
        }

        .empty-message {
            text-align: center;
            padding: 40px;
            color: #888;
            font-size: 1.1em;
        }

        .mood-selector {
            margin-bottom: 15px;
            display: flex;
            flex-wrap: wrap;
            gap: 10px;
        }

        .mood-selector label {
            margin-right: 15px;
            cursor: pointer;
            white-space: nowrap;
        }

        .mood-icon {
            margin-right: 5px;
            font-size: 1.2em;
        }

        .privacy-notice {
            font-size: 0.9em;
            color: #888;
            margin-top: 10px;
            text-align: center;
        }

        footer {
            text-align: center;
            margin-top: 50px;
            padding: 20px;
            color: #888;
            font-size: 0.9em;
        }

        /* 响应式设计 */
        @media (max-width: 768px) {
            .container {
                padding: 15px;
            }

            header {
                padding: 15px 0;
                margin-bottom: 20px;
            }

            h1 {
                font-size: 1.8em;
            }

            .description {
                font-size: 1em;
            }

            .post-form {
                padding: 15px;
            }

            .mood-selector {
                flex-direction: column;
                gap: 8px;
            }

            .mood-selector label {
                margin-right: 0;
            }

            .post {
                padding: 15px;
            }
        }

        @media (max-width: 480px) {
            .container {
                padding: 10px;
            }

            header {
                padding: 12px 0;
            }

            h1 {
                font-size: 1.5em;
            }

            textarea {
                padding: 10px;
                min-height: 120px;
            }

            .btn {
                width: 100%;
                padding: 12px;
            }
        }

        .mood-selector {
            display: flex;
            gap: 10px;
            flex-wrap: wrap;
            margin-bottom: 20px;
        }

        .mood-option {
            position: relative;
        }

        .mood-selector label {
            display: flex;
            align-items: center;
            padding: 8px 20px;
            border-radius: 30px;
            background: rgba(255, 255, 255, 0.9);
            border: 2px solid #ffd1dc;
            cursor: pointer;
            transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
        }

        .mood-selector label:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 10px rgba(255, 182, 193, 0.2);
        }

        .mood-selector input[type="radio"]:checked + label {
            background: linear-gradient(135deg, #ff8fab 0%, #ffb6c1 100%);
            border-color: #ff6b8b;
            color: white;
            box-shadow: 0 4px 15px rgba(255, 107, 139, 0.3);
        }

        .mood-icon {
            margin-right: 8px;
            font-size: 1.3em;
            transition: filter 0.3s;
        }

        .mood-selector input[type="radio"]:checked + label .mood-icon {
            filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.1));
        }

    </style>
</head>
<body>
<div class="container">
    <header>
        <h1>心灵树洞</h1>
        <p class="description">在这里，你可以匿名分享你的心事、秘密或烦恼</p>
    </header>

    <div class="post-form">
        <form method="post" novalidate>
            {% csrf_token %}
            <h2>写下你想说的话</h2>
            <div class="mood-selector">
                {% for radio in form.mood %}
                    <div class="mood-option">
                        {{ radio.tag }}
                        <label for="{{ radio.id_for_label }}">
                            <span class="mood-icon">
                                {% if radio.choice_label == "开心" %}😊
                                {% elif radio.choice_label == "难过" %}😢
                                {% elif radio.choice_label == "愤怒" %}😠
                                {% elif radio.choice_label == "困惑" %}😕
                                {% elif radio.choice_label == "爱" %}❤️{% endif %}
                            </span>
                            {{ radio.choice_label }}
                        </label>
                    </div>
                {% endfor %}
            </div>
            {{ form.content }}
            <button type="submit" class="btn">匿名发布</button>
            <p class="privacy-notice">所有内容将匿名发布，不会收集任何个人信息</p>
            <div class="mt-2 text-muted small" id="char-counter">剩余字数：500</div>
        </form>
    </div>

    <div class="posts-container" id="posts-container">
        <h2>树洞里的声音</h2>
        <div id="posts-list">
            {% for entry in entries %}
                <div class="post">
                    <div class="post-meta">
                    <span class="mood-badge">
                        {% with mood=entry.get_mood_display %}
                            {% if mood == "开心" %}😊
                            {% elif mood == "难过" %}😢
                            {% elif mood == "愤怒" %}😠
                            {% elif mood == "困惑" %}😕
                            {% elif mood == "爱" %}❤️{% endif %}
                            {{ mood }}
                        {% endwith %}
                    </span>
                        <span class="post-time">{{ entry.created_at|date:"Y-m-d H:i" }}</span>
                    </div>
                    <div class="post-content">{{ entry.content }}</div>
                </div>
            {% empty %}
                <div class="empty-message" id="empty-message">
                    树洞现在空空的，成为第一个分享的人吧...
                </div>
            {% endfor %}
        </div>
    </div>

    <footer>
        <p>心灵树洞 &copy; 2023 | 这是一个安全的倾诉空间</p>
        <p>如果你需要专业心理帮助，请拨打心理援助热线：12320</p>
    </footer>
</div>

<script>
    // 实时字数统计
    document.getElementById('id_content').addEventListener('input', function () {
        const maxLength = 500;
        const remaining = maxLength - this.value.length;
        const counter = document.getElementById('char-counter');
        counter.textContent = `剩余字数：${remaining}`;

        // 动态改变颜色
        counter.style.color = remaining < 10 ? '#dc3545' :
            remaining < 50 ? '#ffc107' : '#888';
    });

    // 初始化时设置正确字数
    window.addEventListener('load', () => {
        const textarea = document.getElementById('id_content');
        const remaining = 500 - textarea.value.length;
        document.getElementById('char-counter').textContent = `剩余字数：${remaining}`;
    });

    document.querySelectorAll('.mood-selector input[type="radio"]').forEach(radio => {
        radio.addEventListener('change', () => {
            document.querySelectorAll('.mood-selector label').forEach(label => {
                label.style.transform = 'scale(1)';
            });
            if (radio.checked) {
                radio.parentElement.style.transform = 'scale(1.05)';
            }
        });
    });

</script>
</body>
</html>
